// 动态获取图片
export const getImg = (file: string) => {
  let path = `../assets/` + file

  try {
    return new URL(path, import.meta.url).href
  } catch (error) {
    console.error('图片不存在:', file, error)
    return '' // 或返回默认图片路径
  }
}

export const downloadBlob = (blob: Blob | undefined, fileName: string, cb?: any) => {
  if (!blob) return
  const url = URL.createObjectURL(blob) // 创建一个临时URL
  const a = document.createElement('a')
  a.href = url
  a.download = fileName
  document.body.appendChild(a)
  // 使用requestAnimationFrame确保DOM已更新
  requestAnimationFrame(() => {
    a.click()

    // 清理
    setTimeout(() => {
      document.body.removeChild(a)
      URL.revokeObjectURL(url) // 释放内存
      cb && cb()
    }, 100)
  })
}
